package com.zhuqi.wx.pay.controller;

import com.zhuqi.wx.pay.notify.WxNotify;
import com.zhuqi.wx.pay.notify.handel.NotifyHandelResponse;
import com.zhuqi.wx.vo.WxPayOrderNotifyResultVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : ZhuQi
 * @version : 时间:2021/12/7 15:05 版本:
 * @description : 微信支付回掉
 * 使用策略模式实现微信支付多种业务场景下的回掉。
 *
 */
@RestController
@RequestMapping("/wx/notify")
public class PayNotifyController {

    private NotifyHandelResponse notifyHandelResponse;

    private WxNotify wxNotify;

    public PayNotifyController(NotifyHandelResponse notifyHandelResponse, WxNotify wxNotify) {
        this.notifyHandelResponse = notifyHandelResponse;
        this.wxNotify = wxNotify;
    }

    /**
     * 微信支付回掉场景1
     * 微信支付v2 版本回掉参数为 XML 版本。最新版为Json
     *
     * @param xmlData 微信支付回掉的参数
     * @return vo 对象
     */
    @GetMapping("/demo1")
    public WxPayOrderNotifyResultVo handleNotifyCanteen(@RequestBody(required = false) String xmlData) {
        return wxNotify.build(xmlData, notifyHandelResponse).handleNotifyResult();
    }

    /**
     * 微信支付回掉场景2
     * 微信支付回掉参数Json
     *
     * @param jsonData 微信支付回掉的参数
     * @return vo 对象
     */
    @GetMapping("/demo2")
    public WxPayOrderNotifyResultVo handleNotifyActivity(@RequestBody(required = false) String jsonData) {
        return wxNotify.build(jsonData, notifyHandelResponse).handleNotifyResult();
    }
}
